package com.teradata.service;

import com.teradata.entities.Content;
import com.teradata.entities.ContentService;
import com.teradata.entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LoginService {
    @Autowired
    private UserService userService;

    @Autowired
    private ContentService contentService;

    public Map<String, Object> login(int id){
        contentService.check(); //验证

        User user = userService.getUserById(id);//通过id读取用户信息

        //通过用户名读取文章列表
        List<Content> contents = contentService.getContentByUserName(user.getName());

        //组装用户信息和文章列表
        Map<String, Object> res = new HashMap<>();

        res.put("user",user);
        res.put("contents",contents);

        return res;
    }
}
